package learn.advance.fileoutputstream1;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

class Demo1OutputStream {

    public static void Test() {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:\\workplace\\新建文件夹\\test\\a.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        try {
            fos.write(97);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


class Demo2OutputStream {
    public static void Test() {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:\\workplace\\新建文件夹\\test\\a.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        try {
            fos.write(49);
            fos.write(48);
            fos.write(48);
        } catch (IOException e) {
            e.printStackTrace();
        }

        byte[] bytes = {65,66,67,68,69};//ABCDE
        //byte[] bytes = {-65,-66,-67,68,69};//烤紻E
        try {
            fos.write(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }

        byte[] b="您好".getBytes();
        System.out.println(Arrays.toString(b));

        try {
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


public class TestFileOutputStream {
    public static void main(String[] args) {
        //Demo1OutputStream.Test();
        Demo2OutputStream.Test();
    }
}
